package leetcode;

import java.util.List;

public class Leetcode82 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode pre = dummy;
        ListNode cur = head;
        while(cur!=null){
            ListNode next = cur.next;
            if(next!=null&&next.val==cur.val){
                while(next!=null&&next.val==cur.val){
                    next = next.next;
                }
                pre.next = next;
                cur = next;
            }else{
                pre = cur;
                cur = cur.next;
            }
        }
        return dummy.next;
    }
}
